package web.servlets;

import domain.Account;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class CheckoutServlet extends HttpServlet {
    private static final String Checkout="WEB-INF/jsp/cart/Checkout.jsp";
    private static final String ERROR = "/WEB-INF/jsp/common/Error.jsp";
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Account account = (Account) session.getAttribute("account");
        if(account!=null) {
            req.getRequestDispatcher(Checkout).forward(req, resp);
        }
        else{
            session.setAttribute("message","Please sign in before you checkout");
            req.getRequestDispatcher(ERROR).forward(req,resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
